package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.repository.CameraLogRepository;
import com.face.server.repository.EventLogRepository;
import com.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.crypto.Data;
import java.text.ParseException;
import java.util.Date;

import static org.springframework.data.mongodb.core.query.Criteria.where;

@RestController
@RequestMapping("raspi/log")
public class RaspiLogController {

    @Autowired
    CameraLogRepository cameraLogRepository;

    @Autowired
    MongoTemplate template;

    @GetMapping
    RespMsg find(@PageableDefault(size = 10000) Pageable pageable,
                 @RequestParam(defaultValue = "0000-00-00") String begin,
                 @RequestParam(defaultValue = "9999-99-99") String end,
                 @RequestParam(defaultValue = "") String input,
                 boolean event) throws ParseException {


        return RespMsg.build(cameraLogRepository
                .findBy(DateUtils.parse(begin), DateUtils.parse(end), input, input, event, pageable));
    }


}
